package homework.six.TCP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) {
        try {
            ServerSocket server = new ServerSocket(8002);
            Socket socket = server.accept();// 接受创建建立
            InputStreamReader reader = new InputStreamReader(socket.getInputStream());// 利用InputStreamReader
                                                                                    // 创建BufferedReader流
            BufferedReader bufferedReader = new BufferedReader(reader);// 输入流读取reader
            PrintWriter writer = new PrintWriter(socket.getOutputStream());// 把处理结果写入输出流，目的地是socket
            String request = bufferedReader.readLine();// 读入请求
            System.out.println("客户端：" + request);
            String line = "Hello,too!";
            writer.println(line);
            writer.flush();
            writer.close();
            bufferedReader.close();
            socket.close();
            server.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
